﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="../../js/header.js"></script>
</head>
<body style="background-color: white;">
    <section class="container-fluid" style="background-color: white;">
        <form class="form-horizontal m15_t" id="form">
            <div class="tab-content">
                <input type="hidden" id="rId" name="rId" value="0">
                <div class="tab-pane fade in active" id="home">
                    <div class="form-group">
                        <label class="wd100 control-label">登陆名称：</label>
                        <div class="wd250 m15_l">
                            <label id="userName" class=" m10_t"></label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>旧密码：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="password" name="oldPassWord" maxlength="40" placeholder="长度必须介于 6 和 40 之间">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>新密码：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="password" name="newPassWord" maxlength="40" autocomplete="off" placeholder="长度必须介于 6 和 40 之间">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>确认新密码：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="password" name="confirmNewPassWord" maxlength="40" autocomplete="off" placeholder="长度必须介于 6 和 40 之间">
                        </div>
                    </div>
                </div>
            </div>
        </form>

    </section>

    <script type="text/javascript">

        var validator = null;

        $(function () {

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/Home/getUser/",
                data: null,
                success: function (response) {
                    if (response.success) {
                        $("#userName").html(response.data.userName);
                    }
                },
                error: function (e) {
                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试。");
                }
            });

            validator = FlashPay.Util.Validator({
                formObj: $("#form"),
                rules: {
                    oldPassWord: {
                        required: true,
                        rangelength: [6, 40]
                    },
                    newPassWord: {
                        required: true,
                        rangelength: [6, 40]
                    },
                    confirmNewPassWord: {
                        required: true,
                        rangelength: [6, 40]
                    },
                },
                messages: {
                    oldPassWord: {
                        required: "长度必须介于 6 和 40 之间",
                        rangelength: "长度必须介于 6 和 40 之间",
                    },
                    newPassWord: {
                        required: "长度必须介于 6 和 40 之间",
                        rangelength: "长度必须介于 6 和 40 之间",
                    },
                    confirmNewPassWord: {
                        required: "长度必须介于 6 和 40 之间",
                        rangelength: "长度必须介于 6 和 40 之间",
                    },
                },
            });

        })

        function save() {

            if (!validator.form()) {
                return false;
            }

            FlashPay.Util.Ajax({
                url: '/Home/EditPassWord',
                type: 'POST',
                data: {
                    oldPassWord: $("input[name='oldPassWord']").val(),
                    newPassWord: $("input[name='newPassWord']").val(),
                    confirmNewPassWord: $("input[name='confirmNewPassWord']").val()
                },
                success: function (response) {
                    if (response.success) {
                        FlashPay.UI.DialogOpener().login();
                        FlashPay.UI.DialogOpener().Tip_success("修改密码成功，请重新登录！");
                        FlashPay.UI.CloseDialog();
                    } else {
                        FlashPay.UI.Tip_short_warning("操作失败！" + response.errorMessage);
                    }
                },
                error: function (json) {
                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试。");
                }
            });
        }
    </script>
</body>
</html>